<template>
  <div id="app">
    <text-item :item="item" v-for="item of arr" :key="item._id"
    @click.native="handleDelet(item._id)"></text-item>
  </div>
</template>

<script>
/* 导入Taro */
import Taro from '@tarojs/taro'

export default {
  data () {
    return {
      msg: 'Hello world!',
      arr:[]
    }
  },
  mounted(){
    this.$http("/api/movie/top250").then(res=>{
      var s = res.data.res;
      var arr=[]
      s.forEach(item=>{
          var {_id,pic,title,rating} = item
          arr.push({
              _id,pic,title,rating,rati:handleStat(rating)
          })
      })
      this.arr=arr
    });
    function handleStat(num) {
      var arr=[]
      for(var i=0;i<5;i++){
          if(num>1.5){
              arr.push(2)
          }else if(num>0.5){
              arr.push(parseInt(num))
          }else{
              arr.push(0)
          }
          num-=2;
      }
      return arr
    }
  },
  methods:{
    handleDelet(id){
      /* get跳转传参 */
      Taro.navigateTo({
        url: `/pages/movie/movie?id=${id}`
      })
    }
  }

}
</script>

<style >
*{
  padding: 0;
  margin: 0;
}
#app{
  padding: 1rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
    
}
</style>
